Signals

Creation

signal attacked
signal item_dropped(name : String, amount : float)

Connection

  • Connect Signals via manual connection in Godot interface.

    • This is possible both for built-in Signals and custom signals created with signal my_signal .

  • Using Object.connect() .

  • Using Signal.connect() .

var player = player.new()

# 5: Connect the 'hit' signal to 'self' via the function '_on_player_hit'.
player.hit.connect(_on_player_hit)

# 6: Connect the 'hit' signal to 'self' via the function '_on_player_hit'; passing parameters ('sword', 100).
player.hit.connect(_on_player_hit.bind("sword", 100))
  • Prefer using Signal.connect()  over Object.connect() , as it references the Signal without using strings.

  • Methods (3,4) and (7,8) are used only if you want to connect not necessarily to 'self', but to another node.

  • About parameter use in connection:

    • Parameters are normally (almost always) passed during signal emission: signal.emit(arg1, arg2)  or emit_signal('signal', arg1, arg2) .

    • Using .bind(arg1, arg2)  during connection implies that parameters arg1  and arg2  will always be passed when the signal is emitted.

Emission

  • Using Object.emit_signal() .

  • Using Signal.emit() .

# Emit the signal.
health_changed.emit()

# Emit the signal; passing parameters (health, max_health).
health_changed.emit(health, max_health)
  • Prefer Signal.emit()  over Object.emit_signal() , for referencing the Signal without strings.